import json
import bson

data1 = {
    "name": "lilisi",
    "age": 18,
    "source": {
        "math": 66.6,
        "english": 88.8,
        "physics": 99.9,
    },
    "height": 180,
    "weight": 70,
}
data2 = {
    "title": "MongoDB",
    "last_editor": "192.168.1.122",
    "last_modified": "new Date('27/06/2011')",
    "body": "MongoDB introduction",
    "categories": ["Database", "NoSQL", "BSON"],
    "revieved": "false",
}

data3 = {
    "address": {"street": "Pizza St", "zipcode": "10003"},
    "coord": [-73.982419, 41.579505],
    "cuisine": "Pizza",
    "name": "Mongo's Pizza",
}

data4 = {
    "age": [1,2,3,4,5,6,7,8,9,10,11,12,13,14, 11111,1111122,11111222,111112222,11111333,11111333],
    "source": [3.1415926,3.1415926,3.1415926,3.1415926,3.1415926,2.71828182,2.71828182,2.71828182,2.71828182,2.71828182]
}

datas = [data1, data2, data3, data4]

if __name__ == "__main__":
    for data in datas:
        # 1.json 序列化
        json_data = json.dumps(data)
        print(f"json_data 长度: {len(json_data)}")
        # print(json_data)

        # 2.bson 序列化
        bson_data = bson.encode(data)
        print(f"bson_data 长度: {len(bson_data)}")
        # print(bson_data)
""" 
json_data 长度: 118
bson_data 长度: 116

json_data 长度: 193
bson_data 长度: 206

json_data 长度: 134
bson_data 长度: 136

结论: bson对 数字,浮点数,数组 序列化有效果
"""